const express = require('express');
const router = express.Router();
const auth = require('../../middlewares/auth');
const validate = require('../../middlewares/validate');
const role = require('../../config/roles');
const submissionController = require('../../controllers/submission.controller');
const multer = require('multer');

// 配置Multer
const upload = multer({
    storage: multer.memoryStorage(),
    limits: {
        fileSize: 50 * 1024 * 1024 // 50MB
    }
});

// 提交实验
router.post(
    '/submit',
    auth(role.STUDENT),
    upload.array('files', 5), // 最多5个文件
    submissionController.submitExperiment
);

// 获取学生提交记录
router.get(
    '/student/:studentId',
    auth(role.STUDENT),
    submissionController.getStudentSubmissions
);

// 下载提交文件
router.get(
    '/:submissionId/file/:fileId',
    auth(role.STUDENT),
    submissionController.downloadSubmissionFile
);

// 评分提交
/*
router.post(
    '/grade/:submissionId',
    auth(role.TEACHER),
    validate.gradeSchema, // 需要实现评分验证
    submissionController.gradeSubmission
);*/

module.exports = router;